﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using QLPKWeb.Models.LinQ.LichLamViec;
using Webdiyer.WebControls.Mvc;

namespace QLPKWeb.BussinessDelegate.LichLamViecDelegate
{
    public class LichLamViec_NguoiChuanBiDelegate
    {
        DBLichLamViecDataContext DBLichLamViec = new DBLichLamViecDataContext();

        public LichLamViec_NguoiChuanBi InsertLichLamViec(LichLamViec_NguoiChuanBi objLichLamViecShare)
        {
            DBLichLamViec.LichLamViec_NguoiChuanBis.InsertOnSubmit(objLichLamViecShare);
            DBLichLamViec.SubmitChanges();
            return GetLichLamViecShareIdMax();
        }

        public bool DeleteLichLamViecByIdLich(int IdLich)
        {
            DBLichLamViec.LichLamViec_NguoiChuanBis.DeleteAllOnSubmit(DBLichLamViec.LichLamViec_NguoiChuanBis.Where(p => p.IDLich == IdLich));
            DBLichLamViec.SubmitChanges();
            return true;
        }

        public List<LichLamViec_NguoiChuanBi> GetAllLichLamViecShareByIDLich(int IDLich)
        {
            return DBLichLamViec.LichLamViec_NguoiChuanBis.Where(p => p.IDLich == IDLich).ToList();
        }

        public LichLamViec_NguoiChuanBi GetLichLamViecShareIdMax()
        {
            if (DBLichLamViec.LichLamViec_NguoiChuanBis.Count() > 0)
                return DBLichLamViec.LichLamViec_NguoiChuanBis.OrderByDescending(p => p.ID).ToList().ElementAtOrDefault(0);
            else return new LichLamViec_NguoiChuanBi();
        }
    }
}